<template>
  <div>
    <el-card style="min-width: 1200px">
      <div class="tableSelectWrap">
        <el-form ref="giveBalance" :model="commandForm" label-width="100px">
          <el-row>
            <el-col :span="7">
              <el-form-item label="选择时间" prop="date">
                <el-date-picker
                  v-model="commandForm.date"
                  style="width: 100%"
                  :default-time="['00:00:00', '23:59:59']"
                  type="datetimerange"
                  start-placeholder="开始时间"
                  end-placeholder="结束时间"
                  value-format="yyyy-MM-dd HH:mm:ss"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="7" :offset="1">
              <el-form-item label="用户ID" prop="inUserNo">
                <el-input
                  v-model="commandForm.inUserNo"
                  placeholder="请输入用户ID"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="7" :offset="1">
              <el-form-item label="赠送状态" prop="givenStatus">
                <el-select
                  v-model="commandForm.givenStatus"
                  clearable
                  style="width: 100%"
                  placeholder="请选择赠送状态"
                >
                  <el-option
                    v-for="item of givenStatus"
                    :key="item.id"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="7" style="min-width: 170px">
              <el-button
                class="width120"
                @click="
                  resetForm('giveBalance');
                "
                >重置</el-button
              >
              <el-button type="primary" class="width120"  @click="
                  () => {
                    this.dataForm = JSON.parse(
                      JSON.stringify(this.commandForm)
                    );
                    this.handleQuery();
                  }
                "
                >查询</el-button
              >
            </el-col>
          </el-row>
        </el-form>
      </div>
    </el-card>
    <el-card
      class="textBox"
      style="min-width: 1200px; margin-bottom: -5px; margin-top: 15px"
    >
      <span class="numBox">
        <span>赠送金额</span>
        <span class="symbol">￥</span>
        <span class="num">{{ info.fmtAmount || 0.0 }}</span>
      </span>
    </el-card>
    <el-card style="margin-top: 15px; min-width: 1200px">
      <div class="switch">
        <el-switch v-model="isFixedTableH" inactive-text="固定表头">
        </el-switch>
      </div>
      <el-table :data="dataList" :height="fixedTableHeight" ref="multipleTable">
        <template slot="empty">
          <el-empty
            :image="require('@/assets/imgs/middleWork/k1.png')"
            :image-size="80"
            description="暂无相关数据"
          ></el-empty>
        </template>
        <el-table-column
          show-overflow-tooltip
          prop="gmtCreated"
          align="center"
          label="创建时间"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.gmtCreated ? scope.row.gmtCreated : "-" }}
            </div>
          </template>
        </el-table-column>

        <el-table-column
          show-overflow-tooltip
          prop="orderNo"
          align="center"
          label="云尘付流水号"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.orderNo ? scope.row.orderNo : "-" }}
            </div>
          </template>
        </el-table-column>

        <el-table-column
          show-overflow-tooltip
          prop="fmtAmount"
          sortable
          align="center"
          label="赠送金额/元"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.fmtAmount ? scope.row.fmtAmount : "0.00" }}
            </div>
          </template>
        </el-table-column>

        <el-table-column
          show-overflow-tooltip
          prop="outUserNo"
          align="center"
          label="转出账户"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.outUserNo ? scope.row.outUserNo : "-" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="inUserNo"
          align="center"
          label="转入账户"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.inUserNo ? scope.row.inUserNo : "-" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="givenStatus"
          align="center"
          label="赠送状态"
        >
          <template>
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
         成功
            </div>
          </template>
        </el-table-column>

        <el-table-column
          show-overflow-tooltip
          prop="act"
          align="center"
          label="操作"
        >
          <!-- <template slot-scope="scope">
            <div>
              <el-button type="text" @click="handleDetails(scope.row)"
                >详情</el-button
              >
            </div>
          </template> -->
          <div>-</div>
        </el-table-column>
      </el-table>
    </el-card>
    <el-pagination
      layout="prev, pager, next, sizes, jumper"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="pageSize"
      :current-page="pageNum"
      :total="total"
      @current-change="pageCurrentChangeHandle"
      @size-change="pageSizeChangeHandle"
    >
    </el-pagination>
    <!-- <details-drawer :drawer.sync="drawer" :info="detailsInfo"   :activeKey="activeKey"></details-drawer> -->
  </div>
</template>

<script>
import mixin from "@/mixins/mixin";
// import detailsDrawer from "@/components/detailsDrawer.vue";
export default {
  name: "giveBalance",
  mixins: [mixin],
  components: {
    // detailsDrawer,
  },
  data() {
    return {
      activeKey: "1",
      mixinViewModuleOptions: {
        getDataListURL: "/api/merchant/balanceBonuses/searchByPage",
        createdIsNeed:false,
      },
      drawer: false,
      dataList:[],
      info: {},
      commandForm: {
        inUserNo: "",
        givenStatus: "",
        date: [],
      },
      detailsInfo: {},
      givenStatus: [
        { id: 1, label: "所有", value: "" },
        { id: 2, label: "成功", value: "1" },
      ],
    };
  },
  created(){
    this.dataForm = JSON.parse(JSON.stringify(this.commandForm));
    this.handleQuery();
  },
  watch: {
    '$store.state.testLine': {
      handler(val){
        if(this.$route.name==this.$options.name){
          if (val) {
            this.$store.commit("changeTestMode", true);
          }
        }
	},
    },
    deep: true
  },
  methods: {
    // handleDetails(row) {
    //   switch (this.activeKey) {
    //     case "1":
    //       this.$http
    //         .get(`/api/merchant/balanceCharge/get?id=${row.id}`)
    //         .then((res) => {
    //           if (res.code === "0000") {
    //             this.detailsInfo = res.data;
    //             this.drawer = true;
    //           }
    //         });
    //       break;
    //     default:
    //       break;
    //   }
    // },
    handleQuery() {
      if (this.dataForm.date && this.dataForm.date.length) {
        this.dataForm.gmtCreatedBegin = this.dataForm.date[0];
        this.dataForm.gmtCreatedEnd = this.dataForm.date[1];
      } else {
        this.dataForm.gmtCreatedBegin = null;
        this.dataForm.gmtCreatedEnd = null;
      }
      this.getStatisticsInfo();
      this.getDataList();
    },
    getStatisticsInfo() {
      this.$http
        .post("/api/merchant/balanceBonuses/balanceBonusesStatistics", this.dataForm)
        .then((res) => {
          if (res.code === "0000") {
            this.info = res.data || {};
          }
        });
    },
  },
};
</script>

<style scoped lang="scss">
.pedding {
  color: #ee8917;
}
.switch {
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
}
.ml {
  margin-left: 50px;
}
.search {
  position: absolute;
  right: 0;
  top: -164px;
}
</style>
